]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
calendar: Fix inclusion of zero-length events
authorSebastian Keller <skeller@gnome.org>
Thu, 4 Nov 2021 13:09:03 +0000 (14:09 +0100)
committerMarge Bot <marge-bot@gnome.org>
Tue, 30 Nov 2021 02:13:24 +0000 (02:13 +0000)
Events with a date time (not just a date) where the end time is missing
or matching the start time were considered to not overlap the selected
interval if they were happening on the start time of the interval. This
was causing such zero-length events to be omitted from the calendar if
they were starting at 0:00.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2023>

js/ui/calendar.js

index ad836355895225cd4f42ed662bdab9c2373bd6c2..a42d70ffb2de86314b64c6dcd19269fddd52211a 100644 (file)
@@ -171,13 +171,26 @@ function _datesEqual(a, b) {
     return true;
 }
 
-function _dateIntervalsOverlap(a0, a1, b0, b1) {
-    if (a1 <= b0)
+/**
+ * Checks whether an event overlaps a given interval
+ *
+ * @param {Date} e0 Beginning of the event
+ * @param {Date} e1 End of the event
+ * @param {Date} i0 Beginning of the interval
+ * @param {Date} i1 End of the interval
+ * @returns {boolean} Whether there was an overlap
+ */
+function _eventOverlapsInterval(e0, e1, i0, i1) {
+    // This also ensures zero-length events are included
+    if (e0 >= i0 && e1 < i1)
+        return true;
+
+    if (e1 <= i0)
         return false;
-    else if (b1 <= a0)
+    if (i1 <= e0)
         return false;
-    else
-        return true;
+
+    return true;
 }
 
 // an implementation that reads data from a session bus service
@@ -343,7 +356,7 @@ class DBusEventSource extends EventSourceBase {
 
     *_getFilteredEvents(begin, end) {
         for (const event of this._events.values()) {
-            if (_dateIntervalsOverlap(event.date, event.end, begin, end))
+            if (_eventOverlapsInterval(event.date, event.end, begin, end))
                 yield event;
         }
     }